package com.junmeng.jdemo.recycler.chat.contextmenu;

import androidx.fragment.app.FragmentActivity;

import com.example.ui.dialog.CommonDialogFragment;
import com.junmeng.jdemo.recycler.chat.contextmenu.base.IMenuViewManager;
import com.junmeng.jdemo.recycler.chat.contextmenu.base.MenuListener;

import java.util.List;

public class MenuViewManager implements IMenuViewManager<MenuInfo,Object> {
    FragmentActivity context;

    public MenuViewManager(FragmentActivity context) {
        this.context = context;
    }


    private MenuListener<MenuInfo,Object> listener;

    public void setMenuListener(MenuListener listener) {
        this.listener = listener;
    }

    @Override
    public void show(List<MenuInfo> menuInfo, Object userData) {
        CommonDialogFragment.newBuilder()
                .setTitle("标题")
                .setTitleBold(true)
                .isContentCenter(false)
                .setContent("menu count=" + menuInfo.size() + ",userData=" + userData)//userdata里可以携带一些对视图位置有用的一些信息
                .setCloseIcon(-1)
                .setPositiveButton("确定", -1, (dialog, which) -> {
                    listener.onMenuClick(null, menuInfo.get(0),userData);
                })
                .setNegativeButton("取消", -1, null)
                .create()
                .show(context.getSupportFragmentManager(), "")
        ;
    }

    @Override
    public void hide() {

    }
}
